package com.sc.auction.auction.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sc.auction.auction.pojo.Atuctionbargain;
import com.sc.auction.auction.service.AtuctionbargainService;
import com.sc.auction.common.util.R;
import com.sc.auction.common.util.Time;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pgc
 * @since 2020-09-01
 */
@RestController
@RequestMapping("/auction/atuctionbargain")
public class AtuctionbargainController extends BaseController{
    @Autowired
    AtuctionbargainService atuctionbargainService;
    @ApiOperation("通过id查询")
    @GetMapping(value = "/getById")
    public R getById(@ApiParam(value = "id")@RequestParam Integer id){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("auctionId",id);
        Atuctionbargain atuctionbargain=atuctionbargainService.getOne(queryWrapper);
        return R.ok().data(" atuctionbargain",atuctionbargain);
    }

    @ApiOperation("查询所有")
    @GetMapping(value = "/getAllbargain")
    public R getById(){
     return R.ok().data("bargainList",atuctionbargainService.list());
    }

    @ApiOperation("增加成交单")
    @PostMapping(value = "/postbargain")
    public R postbargain(@ApiParam(value = "订单")Atuctionbargain atuctionbargain){
        atuctionbargain.setCreationDate(Time.getDate());
      boolean a=atuctionbargainService.save(atuctionbargain);
        if(a){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation("删除成交单")
    @DeleteMapping(value = "/deletebargain")
    public R deletebargain(@ApiParam(value = "订单")@RequestParam Integer id){
        boolean a=atuctionbargainService.removeById(id);
        if(a){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation("修改成交单")
    @PutMapping(value = "/putbargain")
    public R putbargain(@ApiParam(value = "订单")Atuctionbargain atuctionbargain){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("auctionId",atuctionbargain.getAuctionId());
        boolean a=atuctionbargainService.update(atuctionbargain,queryWrapper);
        if(a){
            return R.ok();
        }else {
            return R.error();
        }
    }
}

